//
//  Tools.m
//  成亲坊项目
//
//  Created by dlios on 15-8-24.
//  Copyright (c) 2015年 dlios. All rights reserved.
//

#import "Tools.h"
#import "URL.h"
@implementation Tools


// 存储数据
+(void)toolsOfSaveLibraryPathName:(NSString *)name data:(NSData *)data
{
  NSString *path = [Tools toolsOfPathFile:name ];
    [data writeToFile:path atomically:YES];
    
}
// 有无文件
+(BOOL)toolsOfHasLibraryPathName:(NSString *)name 
{
    NSString *path = [Tools toolsOfPathFile:name];
    NSFileManager *manager = [[NSFileManager alloc]init];
    BOOL has = [manager fileExistsAtPath:path];
    return has;
}
//文件路径 取data
+(NSString *)toolsOfPathFile:(NSString *)name
{
    NSArray *arr = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *path = [NSString stringWithFormat:@"%@/Caches/%@",[arr objectAtIndex:0],name];
    return path;

}

// 解析
+(id)toolsOfJsonDataType: (NSString *)str  fileName:(NSString *)name
{
    NSString *path = [Tools toolsOfPathFile:name];
    NSData *data = [NSData dataWithContentsOfFile:path];
    if ([str isEqualToString:dicType]) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        return dic;
    }
    else if ([str isEqualToString:arrType])
    {
        NSArray *arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        return arr;
    }
    
    return nil;
}


@end
